<template>
  <div>
    <div v-show="!isDetail" class="page-index">
      <div class="page-left">
        <ClassifyTreeSilder @nodeClick="nodeClick" ref="treeSilder" />
      </div>
      <div class="page-right">
        <div class="table-search">
          <el-form inline>
            <el-form-item label="组织名称">
              <el-input v-model="queryParams.partyOrgName" size="mini" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="日期">
              <el-date-picker
                v-model="queryDate"
                type="daterange"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                value-format="yyyy-MM-dd"
                @change="queryDateChange"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button size="mini" type="primary" @click="search">搜索</el-button>
              <el-button size="mini" @click="reset">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="table-box">
          <el-table
            :data="tableData"
            ref="table"
            height="100%"
          >
            <el-table-column prop="partyOrgName" label="党组织名称" align="center" min-width="180" />
            <el-table-column prop="totalPoints" label="总积分" align="center" width="180" />
            <el-table-column prop="acquiredThisYear" label="本年获取" align="center" width="180" />
            <el-table-column prop="acquiredThisMonth" label="本月获取" align="center" width="180" />
            <el-table-column label="操作" align="center" width="80">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="mini"
                  @click="openDetail(scope.row)"
                >查看详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getData"
        />
      </div>
    </div>
    <detailPage v-show="isDetail" ref="detailPage" @goback="goback" />
  </div>
</template>
<script>
import ClassifyTreeSilder from '@/components/classifyTree/classifyTreeSilder.vue'
import detailPage from './components/detail'
import { queryByCondition } from '@/api/cadreBusiness/IntegralStatistics'
export default {
  components: {
    ClassifyTreeSilder,
    detailPage
  },
  data () {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        startTime: '',
        endTime: '',
        partyOrgName: ''
      },
      queryDate: [],
      total: 0,
      tableData: [
        { id: 1 }
      ],
      isDetail: false
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    getData () {
      queryByCondition(this.queryParams).then((res) => {
        this.tableData = res?.data?.records || []
        this.total = res?.data?.total || 0
      })
    },
    search () {
      this.queryParams.pageNo = 1
      this.getData()
    },
    openDetail (row) {
      this.isDetail = true
      this.$refs.detailPage.init(row)
    },
    nodeClick (data, node, dom) {
      // this.queryParams.partyOrgId = data?.id || null
      this.queryParams.partyOrgName = data?.fullNamePartyOrg || null
      this.search()
    },
    queryDateChange (val) {
      this.queryParams.startTime = val[0]
      this.queryParams.endTime = val[1]
    },
    goback () {
      this.isDetail = false
      this.getData()
    },
    reset () {
      this.queryParams.startTime = ''
      this.queryParams.endTime = ''
      this.queryParams.partyOrgName = ''
      this.queryDate = []
      this.search()
    }
  }
}
</script>
<style scoped lang="scss">
.page-index {
  display: flex;
  padding-top: 24px;
  .page-left {
    height: calc(100vh - 130px);
    overflow-y: auto;
    width: 300px;
  }
  .page-right {
    flex: 1;
    overflow-x: hidden;
    // .table-search {
    //   display: flex;
    //   justify-content: space-between;
    //   padding-left:16px;
    // }
    .table-box {
      height: calc(100vh - 230px);
    }
  }
}

</style>
